/***
 * CaRComp Translator
 * 
 * Copyright (C) 2011 Taylor L. Riche
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ***/

package translator.objects;

import java.io.PrintStream;

public class Port extends Entity {
	
	public enum Direction {
		IN, OUT
	}

	protected Direction dir;
	protected String compID;
	protected String type;
	
	/**
	 * @param name
	 */
	public Port(String ident, String name, String dir, String type) {
		super(ident, name);
		if(dir.equals(Direction.IN.toString()) || dir.equals(Direction.IN.toString().toLowerCase())) {
			this.dir = Direction.IN;
		}
		else if(dir.equals(Direction.OUT.toString()) || dir.equals(Direction.OUT.toString().toLowerCase())) { 
			this.dir = Direction.OUT;
		}
		this.compID = "";
		this.type = type;
	}

	@Override
	public void generateCode(PrintStream fo) {
		if(this.dir == Direction.IN) {
			fo.println("\t\tself.add_port(\"" + this.getName() + "\", None)");
		}
		else if(this.dir == Direction.OUT) {
			fo.println("\t\tself.add_port(\"" + this.getName() + "\", None, True)");
		}
		else {
			
		}
		
	}
	
	public void setCompID(String compID) {
		this.compID = compID;
		//System.err.println(this + ":" + this.compID);
	}
	
	public String getCompID() {
		return this.compID;
	}

}
